# -*- coding: utf-8 -*-
from PyQt4 import QtCore , QtGui
from lib.customUI import customUI
from lib.papyDB import papyDB , tableInfo
from lib.papyDBTable import *
from lib import globalVar

class assetMaker_UI(customUI):
    def __init__(self,parent=None):
        QtGui.QMainWindow.__init__(self , parent)
        customUI.__init__(self)



    def createPrjSeqShot(self):
        self.prj_grp , self.prj_cb =  self.grpCBox("Project")
        prjList = PROJECT.search('prjCodeName')
#        print prjList
        map(lambda x:self.prj_cb.addItem(x) , prjList ) 
        self.seq_grp , self.seq_cb =  self.grpCBox("Sequence")
        self.shot_grp , self.shot_cb =  self.grpCBox("Shot")
        assetType =  self.grpCBox("Asset Type")
        self.assetType_grp = assetType[0] 
        self.assetType_CBox = assetType[1]        
        map(lambda x:self.assetType_CBox.addItem(x) , papyDB.assetType )        
        
        self.prj_cb.currentIndexChanged.connect( self.initSeqO )
        self.seq_cb.currentIndexChanged.connect( self.initShotO )
        
        self.pssLayout = QtGui.QHBoxLayout()
        self.pssLayout.addWidget(self.prj_grp)
        self.pssLayout.addWidget(self.seq_grp)
        self.pssLayout.addWidget(self.shot_grp)
        self.pssLayout.addWidget(self.assetType_grp) 



    def initSeqO(self):        
        self.initSeq('--Master--')
        
    def initShotO(self):
        self.initShot('--Global--')



    def createAssetTag(self):
        self.assetName_grp , self.assetName_line  =  self.grpLineEdt( "Asset Name")
        self.assetTag_grp , self.assetTag_line  =  self.grpLineEdt( "Asset Tag")
        self.nt_layout = QtGui.QHBoxLayout()        
        self.nt_layout.addWidget(self.assetName_grp)
        self.nt_layout.addWidget(self.assetTag_grp)



    def createCancelDoBtn(self):
        self.makeAsset_btn , self.cancel_btn = self.cancelDoBtn("MakeAsset")      
        self.btn_layout = QtGui.QHBoxLayout()        
        self.btn_layout.addWidget(self.cancel_btn)
        self.btn_layout.addWidget(self.makeAsset_btn)



    def setUI(self):                     
        self.mainWidget = QtGui.QWidget( )        
        self.createPrjSeqShot()       
        self.createAssetTag()
        
        desc_label = self.label("[ Description ]")
        self.desc_txtEdt = self.txtEditor()        
        self.createCancelDoBtn()        
        
        mainGridLayout = QtGui.QGridLayout(self.mainWidget)        
        mainGridLayout.addLayout(self.pssLayout, 0, 0, 1, 1)
        mainGridLayout.addLayout(self.nt_layout, 1, 0, 1, 1)
        mainGridLayout.addWidget(desc_label, 2, 0, 1, 1)
        mainGridLayout.addWidget(self.desc_txtEdt, 3, 0, 1, 1)
        mainGridLayout.addLayout(self.btn_layout, 4, 0, 1, 1)       
        
        self.setCentralWidget(self.mainWidget)
        self.setWindowTitle("Asset Maker")
        self.setGeometry(QtCore.QRect(50,600,405,300))
        self.show()
        self.prj_cb.setCurrentIndex(1)
        self.prj_cb.setCurrentIndex(0)
        


if __name__ == '__main__':
    import sys    
    app = QtGui.QApplication(sys.argv)
    ui = assetMaker_UI()
    ui.setUI()
    app.exec_()
        
        
        